<template>
  <el-card shadow="never" style="margin: 20px 0">
    <div class="title">
      <h3 v-if="productType == 1">加购商品TOP20</h3>
      <h3 v-else>成交商品TOP20</h3>
      <el-button>导出</el-button>
    </div>
    <el-table :data="tableData" style="width: 100%" :header-cell-style="{ background: '#fafafa', color: '#909399' }">
      <el-table-column label="排名" width="80">
        <template #default="scope">
          <div style="padding-left: 5px"> {{ scope.$index + 1 }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="product_no" label="商品编号" width="200" />
      <el-table-column prop="info" label="商品信息">
        <template #default="scope">
          <div class="product">
            <el-image class="cover" :src="scope.row.cover" fit="cover"></el-image>
            <div class="info">
              <div class="product_name">{{ scope.row.product_name }}</div>
              <div class="description">{{ scope.row.description }}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <template v-if="productType == 1">
        <el-table-column prop="purchase_count" label="加购数量" width="200" />
        <el-table-column prop="purchase_num" label="加购人数" width="200" />
      </template>
      <template v-else>
        <el-table-column prop="purchase_num" label="成交金额(元)" width="200" />
        <el-table-column prop="purchase_count" label="商品单价(元)" width="200" />
      </template>
      <template #empty>
        <div class="empty">
          <img class="empty_img" src="@/assets/noData.png" alt="" />
          <div>暂无数据</div>
        </div>
      </template>
    </el-table>
  </el-card>
</template>

<script lang="ts" setup>
  import { ref, defineExpose } from 'vue'
  const productType = ref(1)
  const tableData = ref([])
  const onTable = (v: any, type: any) => {
    productType.value = type
    tableData.value = v
  }
  defineExpose({
    onTable
  })
</script>
<style lang="scss" scoped>
  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 14px;
    margin-bottom: 24px;
    border-bottom: 1px solid #eaeaea;
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #35383a;
  }
  .product {
    display: flex;
    align-items: center;
    .cover {
      width: 40px;
      height: 40px;
      margin-right: 8px;
    }
    .info {
      font-weight: 300;
      font-family: STHeitiSC-Light, STHeitiSC;
      .product_name {
        height: 20px;
        font-size: 14px;
        color: #33302d;
        line-height: 14px;
      }
      .description {
        width: 432px;
        height: 12px;
        font-size: 12px;
        font-weight: 300;
        color: #969696;
        line-height: 12px;
      }
    }
  }
  .empty {
    margin: 100px 0;
    .empty_img {
      transform: translateX(13%);
    }
  }
</style>
